package com.kantboot.business.shop.repository;

import com.kantboot.business.shop.domain.entity.BusShopAddressInUserAccount;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface BusShopAddressInUserAccountRepository
        extends JpaRepository<BusShopAddressInUserAccount,Long> {


    /**
     * 根据用户id修改isDefault
     */
    @Transactional
    @Modifying
    @Query("UPDATE BusShopAddressInUserAccount SET isDefault = :isDefault WHERE userAccountId = :userAccountId")
    void updateIsDefaultByUserAccountId(@Param("isDefault") Boolean isDefault, @Param("userAccountId") Long userAccountId);


    List<BusShopAddressInUserAccount> getByUserAccountId(Long userAccountId);


    @Query("SELECT a FROM BusShopAddressInUserAccount a WHERE a.id = :id")
    BusShopAddressInUserAccount findBy(Long id);

}
